/*
3.Tree Traversals Again 是2014年秋季PAT甲级考试真题，稍微要动下脑筋，想通了其实程序很基础，建议尝试。
*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define maxsize 31


struct Tree {
    int data;
    int left;
    int right;
} T[maxsize];

typedef struct Tree* pTree;

int read() {
    int N, root;
    scanf("%d\n", &N);
    char str[6];
    int element;
    int root_pos = 0;
    int cntarray[N+1];
    int savestack[N];
    int pos = 0;
    for (int i=0; i<N+1; i++) {cntarray[i]=0;}
    for (int i=0; i<2*N; i++) {
        scanf("%s %d\n", str, &element);
        if (i ==0) {root = element;}
        // printf("read: %s %d\n", str, element);
        if (strcmp(str, "Push")== 0) {
            T[element].data = element;
            savestack[pos] = element;
            pos++;
            T[element].left = -1;
            T[element].right = -1;
            if (root_pos>0) {
                if (cntarray[T[root_pos].data]==1) {
                    T[root_pos].left=element;
                } else {
                    T[root_pos].right=element;
                }
            } 
        } else {
            pos--;
            element = savestack[pos];
            // printf("pop: %d\n",element);
            
        }
        cntarray[element]++;
        root_pos = element;
        // printf("%d\n",element);
    }
    return root;
}

void postordertrav(int R) {
    static int flag = 0;
    if (R != -1) {
        postordertrav(T[R].left);
        postordertrav(T[R].right);
        if (flag) printf(" ");
        else flag = 1;
        printf("%d", T[R].data);
    }
}

int main(int argc, char* argv[]) {
    int root = read();
    postordertrav(root);
    return 0;
}